package com.xunyin.enums;


/**
 * @author jthong
 * @Description:设备型号标识
 * @Version 1.0.0
 * @Date 2019/12/26 16:18
 */
public enum DeviceModelEnum {
    /***
     * DH
     */
    MODEL_DH(1, "DH2"),
    /***
     * TL
     */
    MODEL_TL(2, "TL2");

    private final String name;
    private final int value;

    DeviceModelEnum(int value, String name) {
        this.name = name;
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    public int getIndex() {
        return value;
    }

    public static DeviceModelEnum parse(Integer value) {
        if (value == null) {
            return throwParseException(value);
        }
        for (DeviceModelEnum e : DeviceModelEnum.values()) {
            if (e.getValue() == value) {
                return e;
            }
        }
        return throwParseException(value);
    }

    private static DeviceModelEnum throwParseException(Integer value) {
        throw new IllegalArgumentException(value + " can not parse to " + DeviceModelEnum.class.getName());
    }

    public static String getNameByValue(Integer value) {
        if (value == null) {
            return "";
        }
        for (DeviceModelEnum e : DeviceModelEnum.values()) {
            if (e.getValue() == value) {
                return e.getName();
            }
        }
        return "";
    }
}
